/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.bugman.entity;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author Flashman
 */
@Entity
@Table(name = "TBUG")
@NamedQueries({
    @NamedQuery(name = "Bug.findAll", query = "SELECT b FROM Bug b")
})
public class Bug implements Serializable {

    public static final String findAll = "Bug.findAll";

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    private Integer id;

    @Column(name = "creation_time", nullable = true)
    @Temporal(TemporalType.TIMESTAMP)
    private Date creationTime;

    @Column(name = "resolving_time", nullable = true)
    @Temporal(TemporalType.TIMESTAMP)
    private Date resolvingTime;

    @Column(name = "title", nullable = true)
    private String title;

    @Lob
    @Column(name = "summary", nullable = true)
    private String summary;

    @ManyToOne
    private User finder;

    @ManyToOne
    private Project project;
    
    @ManyToOne
    private Status status;
    
    @ManyToOne
    private Importance importance;

    @OneToMany(mappedBy = "bug")
    private List<Comment> comments;

    @ManyToMany(mappedBy = "bugs")
    private List<User> solvers;

    public Bug() {
    }

    public Bug(String title, String summary) {
        this.setTitle(title);
        this.setSummary(summary);
    }

    public Date getCreationTime() {
        return creationTime;
    }

    public void setCreationTime(Date creationTime) {
        this.creationTime = creationTime;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Date getResolvingTime() {
        return resolvingTime;
    }

    public void setResolvingTime(Date resolvingTime) {
        this.resolvingTime = resolvingTime;
    }

    public String getSummary() {
        return summary;
    }

    public void setSummary(String summary) {
        this.summary = summary;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public User getFinder() {
        return finder;
    }

    public void setFinder(User finder) {
        this.finder = finder;
    }

    public List<Comment> getComments() {
        return comments;
    }

    public void setComments(List<Comment> comments) {
        this.comments = comments;
    }

    public Importance getImportance() {
        return importance;
    }

    public void setImportance(Importance importance) {
        this.importance = importance;
    }

    public Status getStatus() {
        return status;
    }

    public void setStatus(Status status) {
        this.status = status;
    }

    public Project getProject() {
        return project;
    }

    public void setProject(Project project) {
        this.project = project;
    }

    public List<User> getSolvers() {
        return solvers;
    }

    public void setSolvers(List<User> solvers) {
        this.solvers = solvers;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Bug)) {
            return false;
        }
        Bug other = (Bug) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return title+" ("+id+")";
    }
}
